placesview: keep reference during network fetching
authorChristian Kellner <christian@kellner.me>
Mon, 5 Sep 2016 11:41:16 +0000 (13:41 +0200)
committerMatthias Clasen <mclasen@redhat.com>
Fri, 9 Sep 2016 20:55:47 +0000 (16:55 -0400)
Analogous to (un)mount operation, we now keep a reference around
during the ongoing operation and make use of the destroyed flag
to check if we are still alive or if we have been cancelled as
a result of the widget being destroyed.

https://bugzilla.gnome.org/show_bug.cgi?id=764979

gtk/gtkplacesview.c

index 5bf15b6ec7878a92ddd92c26840ed737e80107bf..0105800bbfa716ee4267c7d037750a037430972d 100644 (file)
@@ -970,8 +970,11 @@ network_enumeration_next_files_finished (GObject      *source_object,
       g_list_free_full (detected_networks, g_object_unref);
     }
 
-  /* avoid to update widgets if the operation was cancelled in finalize */
-  if (priv->listbox != NULL)
+  g_object_unref (view);
+
+  /* avoid to update widgets if we are already destroyed
+     (and got cancelled s a result of that) */
+  if (!priv->destroyed)
     {
       update_network_state (view);
       update_loading (view);
@@ -997,6 +1000,7 @@ network_enumeration_finished (GObject      *source_object,
         g_warning ("Failed to fetch network locations: %s", error->message);
 
       g_clear_error (&error);
+      g_object_unref (GTK_PLACES_VIEW (user_data));
     }
   else
     {
@@ -1036,6 +1040,7 @@ fetch_networks (GtkPlacesView *view)
   gtk_places_view_set_fetching_networks (view, TRUE);
   update_network_state (view);
 
+  g_object_ref (view);
   g_file_enumerate_children_async (network_file,
                                    "standard::type,standard::target-uri,standard::name,standard::display-name,standard::icon",
                                    G_FILE_QUERY_INFO_NONE,